package com.mischa.atc.gui;

import java.awt.Canvas;
import java.awt.Graphics;
import java.awt.Image;
import java.awt.Rectangle;

public class DoubleBufferedCanvas extends Canvas {	
	private static final long serialVersionUID = 1L;

	@Override
	public void update(Graphics g) {
		Graphics offgc;
		Image offscreen = null;
		Rectangle box = g.getClipBounds();

		// create the offscreen buffer and associated Graphics
		offscreen = createImage(box.width, box.height);
		offgc = offscreen.getGraphics();
		// clear the exposed area
		offgc.setColor(getBackground());
		offgc.fillRect(0, 0, box.width, box.height);
		offgc.setColor(getForeground());
		// do normal redraw
		offgc.translate(-box.x, -box.y);
		paint(offgc);
		// transfer offscreen to window
		g.drawImage(offscreen, box.x, box.y, this);
	}
	
	
	
}
